package com.xjm.ips.controller.salary;

import com.xjm.ips.entity.AjaxJson;
import com.xjm.ips.entity.MyPage;
import com.xjm.ips.entity.Salary;
import com.xjm.ips.service.SalaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/salary/sob")
public class SalarySobController {
    @Autowired
    SalaryService salaryService;

    @GetMapping("/")
    public MyPage getAllSalaries(@RequestParam(defaultValue = "1") Integer pageNo, @RequestParam(defaultValue = "10") Integer pageSize){
       return salaryService.getAllSalaries(pageNo,pageSize);
    }

    @PostMapping("/")
    public AjaxJson addSalarySob(@RequestBody Salary salary){
        if(salaryService.addSalarySob(salary)==1){
            return AjaxJson.ok("添加工资账套成功!");
        }
        return AjaxJson.error("添加工资账套失败!");
    }

    @PutMapping("/")
    public AjaxJson updateSalarySob(@RequestBody Salary salary){
        if(salaryService.updateSalarySob(salary)==1){
            return AjaxJson.ok("更新工资账套成功!");
        }
        return AjaxJson.error("更新工资账套失败!");
    }

    @DeleteMapping("/{id}")
    public AjaxJson deleteSalarySob(@PathVariable Integer id){
        if(salaryService.deleteSalarySob(id)==1){
            return AjaxJson.ok("删除工资账套成功!");
        }
        return AjaxJson.error("删除工资账套失败!");
    }

    @DeleteMapping("/bitchDeleteSalarySob")
    public AjaxJson bitchDeleteSalarySob(Integer[] ids){
        if(salaryService.bitchDeleteSalarySob(ids) == ids.length){
            return AjaxJson.ok("批量删除成功!");
        }
        return AjaxJson.error("批量删除失败!");
    }
}
